﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

//https://leetcode.cn/problems/remove-linked-list-elements/
//1.删除链表中等于给定值 val 的所有节点
//输入：head = [1, 2, 6, 3, 4, 5, 6], val = 6
//输出：[1, 2, 3, 4, 5]
struct ListNode {
	int val;
	struct ListNode* next;
};

struct ListNode* removeElements(struct ListNode* head, int val)
{
	struct ListNode* phead = NULL;
	struct ListNode* pcur = NULL;
	while (head)
	{
		if (head->val != val)
		{
			if (phead == NULL)
			{
				phead = head;
				pcur = phead;
			}
			else
			{
				pcur->next = head;
				pcur = head;
			}
		}
		head = head->next;
	}
	if(pcur)
		pcur->next = NULL;
	return phead;
}
int main()
{

	return 0;
}

